package com.inspur.cloud.service.dataspace;

import com.inspur.cloud.dao.dataspace.UserResourceRelationDao;
import com.inspur.cloud.entity.dataspace.UserEntity;
import com.inspur.cloud.entity.dataspace.UserResourceRelationEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class UserResRelationSerivce {
    @Autowired
    private UserResourceRelationDao userResourceRelationDao;

    public  List<UserResourceRelationEntity> findAll(Specification<UserResourceRelationEntity> specification){
        return userResourceRelationDao.findAll(specification);
    }
    public void save(UserResourceRelationEntity userResourceRelationEntity){
        userResourceRelationDao.save(userResourceRelationEntity);
    }
    public void delete(UserResourceRelationEntity userResourceRelationEntity){
        userResourceRelationDao.delete(userResourceRelationEntity);
    }
    public List<Integer> findUserIdByUserIdIn(List<Integer> userIdList){
        return userResourceRelationDao.findUserIdByUserIdIn(userIdList);
    }
    public UserResourceRelationEntity findByResourceIdAndUserId(Integer resourceId, Integer userId){
        return userResourceRelationDao.findByResourceIdAndUserId(resourceId,userId);
    }
    public UserResourceRelationEntity findByResourceIdAndUserIdAndResourceType(Integer resourceId, Integer userId, String resourceType){
        return userResourceRelationDao.findFirstByResourceIdAndUserIdAndResourceType(resourceId,userId,resourceType);
    }
    public List<UserResourceRelationEntity> findAllResourceIdAndUserIdAndResourceType(Integer resourceId, Integer userId,String resourceType){
        return userResourceRelationDao.findAllResourceIdAndUserIdAndResourceType(resourceId,userId,resourceType);
    }
    public UserResourceRelationEntity findFirstByResourceIdAndUserIdAndResourceType(Integer resourceId,Integer userId,String resourceType){
        return userResourceRelationDao.findFirstByResourceIdAndUserIdAndResourceType(resourceId,userId,resourceType);
    }
    public UserResourceRelationEntity findFirstByUserIdAndResourceType(Integer userId,String resourceType){
        return userResourceRelationDao.findFirstByUserIdAndResourceType(userId,resourceType);
    }
    public List<UserResourceRelationEntity> findByResourceIdAndResourceType(Integer resourceId,String resourceType){
        return userResourceRelationDao.findByResourceIdAndResourceType(resourceId,resourceType);
    }
    public  List<UserResourceRelationEntity> findByUserIdAndResourceType(Integer resourceId, String resourceType){
        return userResourceRelationDao.findByUserIdAndResourceType(resourceId,resourceType);
    }
    @Transactional(transactionManager = "transactionManagerDataspace")
    public Integer delByResourceId(Integer resourceId, String resourceType){
        return userResourceRelationDao.delByResourceId(resourceId,resourceType);
    }
    @Transactional(transactionManager = "transactionManagerDataspace")
    public Integer delByUserId(Integer userId){
        return userResourceRelationDao.delByUserId(userId);
    }
    @Transactional(transactionManager = "transactionManagerDataspace")
    public Integer delByResourceIdExcludeOwner(Integer resourceId, Integer userId, String resourceType){
        return userResourceRelationDao.delByResourceIdExcludeOwner(resourceId,userId,resourceType);
    }
    @Transactional(transactionManager = "transactionManagerDataspace")
    public Integer delByResourceIdWhereIdIn(Integer resourceId,List<Integer> userList,String resourceType){
        return userResourceRelationDao.delByResourceIdWhereIdIn(resourceId,userList,resourceType);
    }
    public  List<String> queryUserNameByResourceId(Integer resourceId, String resourceType){
        return userResourceRelationDao.queryUserNameByResourceId(resourceId,resourceType);
    }
    public List<UserEntity> queryUserByResourceId(Integer resourceId, String resourceType){
        return userResourceRelationDao.queryUserByResourceId(resourceId,resourceType);
    }
    public List<UserEntity> queryMySonByResourceId(Integer resourceId,String resourceType,Integer parentId){
        return userResourceRelationDao.queryMySonByResourceId(resourceId,resourceType,parentId);
    }
    public List<UserEntity> queryUserByResourceIdExceptOwner(Integer resourceId,String resourceType,Integer owner){
        return userResourceRelationDao.queryUserByResourceIdExceptOwner(resourceId,resourceType,owner);
    }
    public List<UserResourceRelationEntity> findByUserIdInAndResourceIdInAndResourceType(List<Integer> userIds, List<Integer> resourceIds, String resourceType){
        return userResourceRelationDao.findByUserIdInAndResourceIdInAndResourceType(userIds,resourceIds,resourceType);
    }
    @Transactional(transactionManager = "transactionManagerDataspace")
    public Integer delByResourceIdList(List<Integer> resourceIdList,String resourceType){
        return userResourceRelationDao.delByResourceIdList(resourceIdList,resourceType);
    }
    public List<Integer> findTennatsByResourceId(Integer resourceId, String resourceType){
        return userResourceRelationDao.findTennatsByResourceId(resourceId,resourceType);
    }
}
